//
//  HDPersonalOrderCell.m
//  HDecoration
//
//  Created by 曹群 on 15/8/16.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDPersonalOrderCell.h"
#import "HDMenuView.h"
#import "HDLearningOrderListViewController.h"
#import "HDPracticeOrderListViewController.h"
#import "HDIncomeViewController.h"

@interface HDPersonalOrderCell ()
@property(nonatomic,strong)HDMenuView *menu;
@property(nonatomic,strong)HDLearningOrderListViewController *learningOrderList;
@property(nonatomic,strong)HDPracticeOrderListViewController *practiceOrderList;
@property(nonatomic,strong)HDIncomeViewController *incomeVC;
@property(nonatomic,strong)UIViewController *currentVC;
@end

@implementation HDPersonalOrderCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.menu];
    }
    return self;
}

- (void)selectMenuIndex:(int)index
{
    if (self.currentVC) {
        if (self.currentVC.view.tag!=100+index) {
            [self.currentVC.view removeFromSuperview];
        } else {
            return;
        }
    }
    switch (index) {
        case 0:     //学车
        {
            [self insertSubview:self.learningOrderList.view belowSubview:self.menu];
            self.currentVC = self.learningOrderList;
            break;
        }
        case 1:     //练车
        {
            [self insertSubview:self.practiceOrderList.view belowSubview:self.menu];
            self.currentVC = self.practiceOrderList;
            break;
        }
        case 2:     //我的收入
        {
            [self insertSubview:self.incomeVC.view belowSubview:self.menu];
            self.currentVC = self.incomeVC;
            break;
        }
        default:
            break;
    }
}

#pragma mark - getters
- (HDMenuView *)menu
{
    if (!_menu) {
        _menu = [[HDMenuView alloc] initWithFrame:CGRectMake(0, 0, APPFRAME.size.width, 44) titleArray:@[@"学车",@"练车",@"我的收入"]];
        _menu.delegate = (id)self;
        _menu.selectedIndex = 0;
    }
    return _menu;
}

- (HDLearningOrderListViewController *)learningOrderList
{
    if (!_learningOrderList) {
        _learningOrderList = [[HDLearningOrderListViewController alloc] init];
        _learningOrderList.view.frame = CGRectMake(0, 44, self.width, self.height-44);
        _learningOrderList.view.tag = 100;
    }
    return _learningOrderList;
}

- (HDPracticeOrderListViewController *)practiceOrderList
{
    if (!_practiceOrderList) {
        _practiceOrderList = [[HDPracticeOrderListViewController alloc] init];
        _practiceOrderList.view.frame = CGRectMake(0, 44, self.width, self.height-44);
        _practiceOrderList.view.tag = 101;
    }
    return _practiceOrderList;
}

- (HDIncomeViewController *)incomeVC
{
    if (!_incomeVC) {
        _incomeVC = [[HDIncomeViewController alloc] init];
        _incomeVC.view.frame = CGRectMake(0, 44, self.width, self.height-44);
        _incomeVC.view.tag = 102;
    }
    return _incomeVC;
}


@end
